package de.karlNet.sambamanager.ldapController;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapModel.LdapObject;
@Controller
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
public class LdapMemberTree extends AbstractNestedTree implements ILdapTree {
	@Autowired
	private OriginalLdapTree originalLdapTree;
	
	@Override
	protected String getInverseAttributeName() {
		return "memberof";
	}

	@Override
	protected List<String> getChildrenOfLdapObject(LdapObject ldapObject) {
		return ldapObject.getMembers();
	}

	@Override
	public String getRootNodeFilter() {
		return "(&(((objectclass=group))(!("
		+ this.getInverseAttributeName() + "=*))))";
	}

	@Override
	public List<LdapObject> searchFor(String searchTerm) {
		return this.originalLdapTree.searchFor(searchTerm);
	}

	public LdapMemberTree() {
	}

	@Override
	public String getBaseDN() {
		return this.baseDN;
	}
}
